<template>
  <a-layout class="layout">
    <Drawer v-model:show="drawerOpen" v-if="isMobile">
      <a-layout-sider
        v-model:collapsed="collapsed"
        breakpoint="lg"
        :collapsed-width="collapsedWidth"
        @collapse="onCollapse"
        @breakpoint="onBreakpoint"
      >
        <div class="logo" />
        <a-menu theme="dark" mode="inline" v-model:selectedKeys="selectedKeys">
          <a-menu-item key="1">
            <user-outlined />
            <span class="nav-text">nav 1</span>
          </a-menu-item>
          <a-menu-item key="2">
            <video-camera-outlined />
            <span class="nav-text">nav 2</span>
          </a-menu-item>
          <a-menu-item key="3">
            <upload-outlined />
            <span class="nav-text">nav 3</span>
          </a-menu-item>
          <a-menu-item key="4">
            <user-outlined />
            <span class="nav-text">nav 4</span>
          </a-menu-item>
        </a-menu>
      </a-layout-sider>
    </Drawer>
    <a-layout-sider
      v-else
      v-model:collapsed="collapsed"
      breakpoint="lg"
      :collapsed-width="collapsedWidth"
      @collapse="onCollapse"
      @breakpoint="onBreakpoint"
    >
      <div class="logo" />
      <a-menu theme="dark" mode="inline" v-model:selectedKeys="selectedKeys">
        <a-menu-item key="1">
          <user-outlined />
          <span class="nav-text">nav 1</span>
        </a-menu-item>
        <a-menu-item key="2">
          <video-camera-outlined />
          <span class="nav-text">nav 2</span>
        </a-menu-item>
        <a-menu-item key="3">
          <upload-outlined />
          <span class="nav-text">nav 3</span>
        </a-menu-item>
        <a-menu-item key="4">
          <user-outlined />
          <span class="nav-text">nav 4</span>
        </a-menu-item>
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header style="background: #fff; padding: 0">
        <menu-unfold-outlined
          v-if="collapsed"
          class="trigger"
          @click="() => (collapsed = !collapsed)"
        />
        <menu-fold-outlined v-else class="trigger" @click="() => (collapsed = !collapsed)" />
      </a-layout-header>
      <a-layout-content
        :style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: '280px' }"
      >
        Content
      </a-layout-content>
      <a-layout-footer style="text-align: center">
        Ant Design ©2018 Created by Ant UED
      </a-layout-footer>
    </a-layout>
  </a-layout>
</template>
<script lang="ts">
import { UserOutlined, VideoCameraOutlined, UploadOutlined, MenuUnfoldOutlined, MenuFoldOutlined, } from '@ant-design/icons-vue';
import { defineComponent, reactive, ref, toRefs } from 'vue';
import Drawer from './tool/Drawer.vue'
export default defineComponent({
  components: {
    UserOutlined,
    VideoCameraOutlined,
    UploadOutlined,
    MenuUnfoldOutlined,
    MenuFoldOutlined,
    Drawer,
  },
  setup() {
    const data = reactive({
      collapsedWidth: 80,
      isMobile:false,
      drawerOpen:false,
    })

    const onCollapse = (collapsed: boolean, type: string) => {
      console.log(collapsed, type);
      if(type == 'responsive'){
        data.collapsedWidth = collapsed?0:80
        data.isMobile = collapsed?true:false
      }else if(type == 'clickTrigger'){
        data.drawerOpen = collapsed?true:false
      }
    };

    const onBreakpoint = (broken: boolean) => {
      console.log(broken);
    };

    return {
      ...toRefs(data),
      selectedKeys: ref<string[]>(['4']),
      onCollapse,
      onBreakpoint,
      collapsed: ref<boolean>(false),
    };
  },
});
</script>

<style scoped>
.layout{
  min-height: 100vh;
}

.logo {
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  margin: 16px;
}

.site-layout-sub-header-background {
  background: #fff;
}

.site-layout-background {
  background: #fff;
}

[data-theme='dark'] .site-layout-sub-header-background {
  background: #141414;
}

.trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}

.trigger:hover {
  color: #1890ff;
}

.site-layout .site-layout-background {
  background: #fff;
}
</style>
